package com.wt.springsamples.model.search;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Field;
import java.util.Date;

@Data
public abstract class TimeSearchModel {

    protected  Date startTime;

    protected  Date endTime;

    public <T>  T getPropertyValue(String propertyName,Class<T> returnType){
        try {
            Field declaredField = this.getClass().getDeclaredField(propertyName);
            declaredField.setAccessible(true);
            Object fieldValue = declaredField.get(this);

            if(fieldValue!=null && fieldValue.getClass().isAssignableFrom(returnType)){
               return  (T)fieldValue;
            }
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return  null;
    }
}
